package org.dromara.system.mq;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.dromara.system.domain.mq.OrderGetStatusParam;
import org.dromara.system.kernel.OrderUpdateKernel;
import org.dromara.system.mq.config.OrderQueueConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
@RabbitListener(queues = OrderQueueConfig.DELAYED_STATUS_QUEUE)
public class OrderGetStatusReceiver {

    @Autowired
    private OrderUpdateKernel orderUpdateKernel;

    @RabbitHandler
    public void receiveMessage(OrderGetStatusParam param, Message message, Channel channel) throws IOException {
        try {
//            log.info("=======执行========主动获取订单状态====================");
            orderUpdateKernel.handleGetOrderStatus(param);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
        }catch (Exception e){
            log.error("执行【主动获取订单状态】异常\n接收内容: {} \n异常{},{}", param.toString(), getClass(), e.getMessage());
        }
    }

}
